package com.aio.news.home.adapter;

import java.util.ArrayList;
import java.util.List;

import com.aidi.lib.TAInjectView;
import com.aio.news.AioApplication;
import com.aio.news.BaseFragment;
import com.aio.news.R;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NewsDetailAdapter extends BaseAdapter {

	private BaseFragment fragment;
	private List<String> contents = new ArrayList<String>();

	public NewsDetailAdapter(BaseFragment mFragment) {
		this.fragment = mFragment;
	}

	public void setPhotoUrl(String url) {
		contents.add(url);
	}

	public void setMessage(List<String> contents) {
		this.contents.addAll(contents);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return contents.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final String item = contents.get(position);
		final ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(fragment.getActivity(),
					R.layout.news_detail_adapter_content_layout, null);
			AioApplication.getInjector().injectView(convertView, holder);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
			holder.text.setVisibility(View.VISIBLE);
			holder.text.setText(item+".");
		return convertView;
	}

	private boolean isPhotoUrl(String content) {
		if (content.startsWith("http://")
				&& (content.endsWith(".jpg") || content.endsWith(".jpeg")
						|| content.endsWith(".png") || content.endsWith(".gif"))) {
			return true;
		} else {
			return false;
		}
	}

	class ViewHolder {
		@TAInjectView(id = R.id.text)
		TextView text;
	}

}
